//about load each js code basing on different dependency
//按不同先后的依赖关系加载各个JS文件
var indexDependencyArray = [
	'base'
	]
define(indexDependencyArray,function ($) {	
	$(document).ready(function(){
		
		require(["owl.carousel"],function(){
			$(window).resize(function(){
				//使slider轮播尺寸始终随屏幕变动自适应
				$('#slider .slideItem').css('height',$(window).height());
			})
			//定义顶部全屏slider轮播前先使其能够自适应屏幕
			$('#slider .slideItem').css('height',$(window).height());
			
			//定义顶部全屏slider轮播
			$('#slider').owlCarousel({
				singleItem: true,
				autoHeight: true,
				transitionStyle: 'fade',
				navigation: true,
				navigationText:['',''],
				pagination: true,
				addClassActive: true,
				afterInit: function(sliderObj){
					sliderContentAnimate(sliderObj);
					$('#slider .slideItem').first().lazyLoadPic();//图片延迟加载JS
					$('#slider .owl-item').css('width',$(window).width());//修复延迟加载导致宽度BUG
				},
				afterMove: function(sliderObj){sliderContentAnimate(sliderObj)},
				beforeMove: function(sliderObj){
					$('#slider .slideItem').lazyLoadPic({animate:false});//图片延迟加载JS
					sliderObj.find('.inner h1,.inner p').removeClass();
				}
			});
			//slider轮播内容动画函数
			function sliderContentAnimate(sliderObj){
				sliderObj.find('.owl-item').each(function(){
					var obj = $(this)
					if(obj.hasClass('active')){
						obj.find('.inner p').css('display','none');
						obj.find('.inner h1').addClass('fadeInUp animated');
						setTimeout(function(){
						obj.find('.inner p').css('display','block');
							obj.find('.inner p').addClass('fadeIn animated');
						},1000)
					}
				})
			}
		})
		
		//图片延迟加载JS
		$('#cases img,#contact,#footer img').lazyLoadPic();
	});
	
	var iconfontFlag = true,
	gridAnimateFlag = true,
	owlCarousel2Flag = true
	
	$(window).scroll(function(){		
		if($(window).scrollTop() > ($('#about').offset().top - $(window).height()) && gridAnimateFlag){
			require(['gridAnimate'],function(){
				//图片延迟加载JS
				$('#girds .girdItem a').lazyLoadPic({animate:false});
				//定义六格动画
				$('#girds').gridAnimate()
				gridAnimateFlag = false
			})
		}
		
		if($(window).scrollTop() > ($('#feature').offset().top - $(window).height()) && iconfontFlag){
			require(["iconfont"],function(){
				iconfontFlag = false
			})
		}
		
		if($(window).scrollTop() > ($('#screenShot').offset().top - $(window).height()) && owlCarousel2Flag){
			//图片延迟加载JS
			$('#screenShot img').lazyLoadPic({animate:false});
			require(["owl.carousel2"],function(){
				//定义截图screenshotSlider轮播
				if($('#screenshotSlider').length) {
					$('#screenshotSlider').owlCarousel2({
						loop:true,
						nav:false,
						dots:false,
						autoplay:true,
						autoplayTimeout:4000,
						smartSpeed:1200,
						lazyLoad:true,
						responsive:{
								0:{items:1},
								551:{items:2},
								768:{items:3},
								1170:{items:5}
						},
					})
				}
				owlCarousel2Flag = false
			})
		}
	});
});
